package context.render.shader;

import context.util.Data;
import java.util.HashMap;
import math.mat3;
import math.mat4;
import math.vec2;
import math.vec2i;
import math.vec3;
import math.vec3i;
import org.lwjgl.opengl.GL20;

public class UniformBuffer
{
    
    private HashMap<Integer, Integer> mQ1i;
    
    private HashMap<Integer, Double> mQ1d;
    
    private HashMap<Integer, vec2i> mQ2i;
    
    private HashMap<Integer, vec2> mQ2d;
    
    private HashMap<Integer, vec3i> mQ3i;
    
    private HashMap<Integer, vec3> mQ3d;
    
    private HashMap<Integer, mat3> mQmat3;
    
    private HashMap<Integer, mat4> mQmat4;
    
    
    public UniformBuffer()
    {
        this.mQ1i = new HashMap<>();
        this.mQ1d = new HashMap<>();
        this.mQ2i = new HashMap<>();
        this.mQ2d = new HashMap<>();
        this.mQ3i = new HashMap<>();
        this.mQ3d = new HashMap<>();
        this.mQmat3 = new HashMap<>();
        this.mQmat4 = new HashMap<>();
    }
    
    
    public void uniform1i(int aLoc, int aData)
    {
        this.mQ1i.put(aLoc, aData);
    }
    
    public void uniform1d(int aLoc, double aData)
    {
        this.mQ1d.put(aLoc, aData);
    }
    
    public void uniform2i(int aLoc, vec2i aData)
    {
        this.mQ2i.put(aLoc, aData);
    }
    
    public void uniform2d(int aLoc, vec2 aData)
    {
        this.mQ2d.put(aLoc, aData);
    }
    
    public void uniform3i(int aLoc, vec3i aData)
    {
        this.mQ3i.put(aLoc, aData);
    }
    
    public void uniform3d(int aLoc, vec3 aData)
    {
        this.mQ3d.put(aLoc, aData);
    }
    
    public void uniformMat3(int aLoc, mat3 aData)
    {
        this.mQmat3.put(aLoc, aData);
    }
    
    public void uniformMat4(int aLoc, mat4 aData)
    {
        this.mQmat4.put(aLoc, aData);
    }
    
    
    public void flush()
    {
        for (int loc : this.mQ1i.keySet())
        {
            GL20.glUniform1i(loc, this.mQ1i.get(loc));
        }
        for (int loc : this.mQ1d.keySet())
        {
            GL20.glUniform1f(loc, this.mQ1d.get(loc).floatValue());
        }
        for (int loc : this.mQ2i.keySet())
        {
            vec2i data = this.mQ2i.get(loc);
            GL20.glUniform2i(loc, data.x, data.y);
        }
        for (int loc : this.mQ2d.keySet())
        {
            vec2 data = this.mQ2d.get(loc);
            GL20.glUniform2f(loc, (float) data.x, (float) data.y);
        }
        for (int loc : this.mQ3i.keySet())
        {
            vec3i data = this.mQ3i.get(loc);
            GL20.glUniform3i(loc, data.x, data.y, data.z);
        }
        for (int loc : this.mQ3d.keySet())
        {
            vec3 data = this.mQ3d.get(loc);
            GL20.glUniform3f(loc, (float) data.x, (float) data.y, (float) data.z);
        }
        for (int loc : this.mQmat3.keySet())
        {
            mat3 data = this.mQmat3.get(loc);
            GL20.glUniformMatrix3(loc, false, Data.get().asFloatBuffer(data.m));
        }
        for (int loc : this.mQmat4.keySet())
        {
            mat4 data = this.mQmat4.get(loc);
            GL20.glUniformMatrix4(loc, false, Data.get().asFloatBuffer(data.m));
        }
        this.mQ1i.clear();
        this.mQ1d.clear();
        this.mQ2i.clear();
        this.mQ2d.clear();
        this.mQ3i.clear();
        this.mQ3d.clear();
        this.mQmat3.clear();
        this.mQmat4.clear();
    }
    
}
